package com.spzx.product.api.factory;

import com.spzx.common.core.domain.R;
import com.spzx.common.core.web.page.TableDataInfo;
import com.spzx.product.api.RemoteProductService;
import com.spzx.product.api.domain.*;
import com.spzx.product.api.domain.vo.SkuStockVo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;

import java.util.List;
import java.util.Map;

public class RemoteProductFallbackFactory implements FallbackFactory<RemoteProductService> {
    private  static final Logger log= LoggerFactory.getLogger(RemoteProductFallbackFactory.class);
    @Override
    public RemoteProductService create(Throwable cause) {
        log.error("商品服务调用失败:{}",cause.getMessage());
        return new RemoteProductService() {
            @Override
            public R<List<ProductSku>> getTopSale(String source) {
                return null;
            }

            @Override
            public R<TableDataInfo> skuList(Integer pageNum, Integer pageSize, SkuQuery skuQuery, String source) {
                return R.fail("获取商品列表失败"+cause.getMessage());
            }

            //====================商品详情六个接口=======================
            @Override
            public R<ProductSku> getProductSku(Long skuId, String source) {
                return R.fail("获取商品sku失败:" + cause.getMessage());
            }

            @Override
            public R<Product> getProductInfo(Long id, String source) {
                return R.fail("获取商品信息失败:" + cause.getMessage());
            }

            @Override
            public R<SkuPrice> getProductSkuPrice(Long skuId, String source) {
                return R.fail("获取商品Sku最新价格信息失败:" + cause.getMessage());
            }

            @Override
            public R<ProductDetails> getProductDetails(Long productId, String source) {
                return R.fail("获取商品详细信息失败:" + cause.getMessage());
            }

            @Override
            public R<Map<String, Long>> getSkuSpecInfo(Long productId, String source) {
                return R.fail("获取商品sku规则详细信息失败:" + cause.getMessage());
            }

            @Override
            public R<SkuStockVo> getSkuStock(Long skuId, String source) {
                return R.fail("获取商品sku库存信息失败:" + cause.getMessage());
            }
            //======================END================================


            //批量获取商品sku最新价格信息
            @Override
            public R<List<SkuPrice>> getSkuPriceList(List<Long> skuIdList, String source) {
                return R.fail("批量获取商品sku最新价格信息失败:" + cause.getMessage());
            }

            @Override
            public R<String> checkAndLock(String orderNo, List<SkuLockVo> skuLockVoList, String source) {
                return R.fail("检查与锁定商品失败:" + cause.getMessage());
            }
        };


    }
}
